<script setup lang="ts">
import { useChannelStore } from '@/stores/channel';
import type { AxiosResData, ChannelItem, CHannelResData } from '@/types';
import axios from 'axios';
import { onMounted, ref } from 'vue';

const channelList = ref<ChannelItem[]>([])
const getChannel = async () => {
  const res = await axios.get<AxiosResData<CHannelResData>>('http://geek.itheima.net/v1_0/channels')
  channelList.value = res.data.data.channels
}

const store = useChannelStore()

onMounted(() => {
  getChannel()
})


</script>
<template>
  <div class="channel-nav">
    <nav class="list">
      <a class="item" :class="{ active: store.channelId === item.id }" href="javascript:;" v-for="item in channelList"
        :key="item.id" @click="store.updateChannelId(item.id)">
        {{ item.name }}
      </a>
    </nav>
  </div>
</template>